package aspectjutil.eventmanager.testmodels;

import aspectjutil.adviseutil.Util;
import aspectjutil.eventmanager.EventInfo;
import aspectjutil.eventmanager.EventInfo.EventerType;
import aspectjutil.eventmanager.label.EventListener;
import aspectjutil.eventmanager.label.OnEvent;
import aspectjutil.eventmanager.label.PreEvent;

@EventListener
public class EventRecipient {
	// For SampleEventClass.CalculationEvent -----------------------------------------------------
	@OnEvent( value={SampleEventClass.CalculationEvent.class}, amongInstancesInThread=false)
	protected static void staticListenerOfCalculationCompletion( EventInfo eventInfo) {
		EventTraceSupporter.getEventTraceList().add( 
				Util.getCallingMethodInfo( Thread.currentThread().getStackTrace(), 1, 1).get( 0)
				);
		EventTraceSupporter.saveEventInfo( eventInfo);
	}
	
	@OnEvent( value={SampleEventClass.CalculationEvent.class}, amongInstancesInThread=true)
	void onCalculationCompletion( EventInfo eventInfo) {
		EventTraceSupporter.getEventTraceList().add( 
				Util.getCallingMethodInfo( Thread.currentThread().getStackTrace(), 1, 1).get( 0)
				);
		EventTraceSupporter.saveEventInfo( eventInfo);
	}
	// -------------------------------------------------------------------------------------------

	
	// For SampleEventClass.PriceChange ----------------------------------------------------------
	@OnEvent( value={SampleEventClass.PriceChange.class}, turnOnEachEvent={1})
	protected static void staticListenerOfPriceChange( EventInfo eventInfo) {
		
		EventTraceSupporter.getEventTraceList().add( 
				Util.getCallingMethodInfo( Thread.currentThread().getStackTrace(), 1, 1).get( 0)
				);
		EventTraceSupporter.saveEventInfo( eventInfo);
	}
	
	protected int price = 0;
	@OnEvent( value={SampleEventClass.PriceChange.class}, turnOnEachEvent={0}, amongInstancesInThread=true)
	void onPriceChange( EventInfo eventInfo) {
		
		EventTraceSupporter.getEventTraceList().add( 
				Util.getCallingMethodInfo( Thread.currentThread().getStackTrace(), 1, 1).get( 0)
				);
		
		EventTraceSupporter.saveEventInfo( eventInfo);
	}
	// -------------------------------------------------------------------------------------------
}
